#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define mems(x,y) memset(x,y,sizeof x)
#define Mp make_pair
#define eb emplace_back
#define gc getchar
#define pc putchar
#define fi first
#define se second
#define il inline
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define drep(i,a,b) for(int i=(a);i>=(b);i--)
#define go(i,u) for(int i=head[u];i;i=e[i].nxt)
	typedef long long ll;
	typedef pair<int,int> pii;
	template<typename T>
	il void read(T &x){
		int f=1;x=0;char c=gc();
		while(c<'0'||c>'9'){
			if(c=='-'){
				f=-1;
			}
			c=gc();
		}
		while(c>='0'&&c<='9'){
			x=x*10+c-48,c=gc();
		}
		x*=f;
	}
	template<typename T,typename ...Args>
	void read(T &x,Args &...args){
		read(x),read(args...);
	}
	template<typename T>
	il void write(T x){
		char buf[43];int len=0;
		if(x<0){
			pc('-'),x=-x;
		}
		do{
			buf[++len]=x%10,x/=10;
		}while(x);
		while(len){
			pc(buf[len--]+'0');
		}
	}
}
using namespace my_std;
const int N=-1,M=-1,inf=0x3f3f3f3f,mod=0;
const ll INF=1ll*inf*inf;
int n,m;
vector<ll> g;
void Yorushika(){
	read(n);
	if(n>3e4){
		return;
	}
	rep(i,1,n){
		ll x;read(x);
		auto it=lower_bound(g.begin(),g.end(),x);
		if(it!=g.end()&&*it==x){
			g.erase(it);
		}else{
			g.insert(it,x);
		}
		x=0;ll y=0,ans=0;
		rep(j,0,(int)g.size()-1){
			ll nx=x+g[j],ny=y+g[(int)g.size()-j-1];
			ans+=ny-max(nx,y);
			x=nx,y=ny;
		}
		printf("%lld\n",ans);
	}
}
signed main(){
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	int t=1;
	//read(t);
	while(t--){
		Yorushika();
	}
}
